package com.younion.action.consumer;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class RequestRouter {

	private static final Log logger = LogFactory.getLog(RequestRouter.class);
	
	private static Properties routemap = new Properties();
	
	private String location;
	
	public void initail() {
		InputStream inputStream = null;
		try {
			if(location == null) {
				inputStream = this.getClass().getResourceAsStream("/request-router.properties");
			} else
				inputStream = new FileInputStream(location);
			
			routemap.load(inputStream);
		} catch (FileNotFoundException e) {
			logger.error("could not found request-router.properties", e);
		} catch (IOException e) {
			logger.error("could not found request-router.properties", e);
		}
	}
	
	public String getRequestConsumer(String serviceName) {
		return routemap.getProperty(serviceName);
	}

	public void setLocation(String location) {
		this.location = location;
	}
}
